Socket
Socket
Sign inDemoInstall

true-case-path

Package Overview
Dependencies
11
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    true-case-path

Given a possibly case-variant version of an existing filesystem path, returns the case-exact, normalized version as stored in the filesystem.


Version published
Weekly downloads
2.1M
decreased by-1.25%
Maintainers
1
Install size
166 kB
Created
Weekly downloads
 

Package description

What is true-case-path?

The true-case-path npm package is designed to provide the true case of a filesystem path on a case-insensitive filesystem. This is particularly useful when working with file systems that do not enforce case sensitivity, such as those on Windows and macOS. It helps in ensuring that the path casing matches the actual casing on the filesystem.

What are true-case-path's main functionalities?

Get true case of a file path

This feature allows you to get the true case of a file path. It returns a promise that resolves to the correctly cased path as a string. If the file does not exist, the promise is rejected with an error.

const trueCasePath = require('true-case-path');

trueCasePath('/users/guest/documents/myfile.txt').then((trueCasePath) => {
  console.log(trueCasePath);
}).catch((error) => {
  console.error(error);
});

Other packages similar to true-case-path

Readme

Source

true-case-path

Usage

trueCasePathSync(<fileSystemPath>)

Description

Given a possibly case-variant version of an existing filesystem path, returns the case-exact, normalized version as stored in the filesystem.

If the input path is a globbing pattern as defined by the 'glob' npm package, only the 1st match, if any, is returned. Only a literal input path guarantees an unambiguous result.

If no matching path exists, undefined is returned. On case-SENSITIVE filesystems, a match will also be found, but if case variations of a given path exist, it is undefined which match is returned.

Platforms

Windows, OSX, and Linux (though note the limitations with case-insensitive filesystems).

Limitations

  • Paths starting with './' are acceptable, but paths starting with '../' are not - when in doubt, resolve with fs.realPathSync() first. An initial '.' and interior '..' instances are normalized, but a relative input path still results in a relative output path. If you want to ensure an absolute output path, apply fs.realPathSync() to the result.
  • On Windows, no attempt is made to case-correct the drive letter or UNC-share component of the path.
  • Unicode support:
    • Be sure to use UTF8 source-code files (with a BOM on Windows)
    • On OSX, the input path is automatically converted to NFD Unicode form to match how the filesystem stores names, but note that the result will invariably be NFD too (which makes no difference for ASCII-characters-only names).

Examples

const trueCasePathSync = require('true-case-path')

trueCasePathSync('/users/guest') // OSX: -> '/Users/Guest'

trueCasePathSync('c:\\users\\all users') // Windows: -> 'c:\Users\All Users'

Attribution

The code for this project was sourced from http://stackoverflow.com/a/33139702/45375

FAQs

Last updated on 26 Aug 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc